<?php
/**
* 咨询中心
* @DateTime 2017-09-04
* @author xyl
*/
class Information extends Admin_Controller
{
	
	function __construct()
	{
		parent::__construct();
		$this->load->model('Information_model','infos');
		
	}
    /**
     * 咨询中心首页
     * @DateTime 2017-09-04
     * @author xyl
     * @return   [type]     [description]
     */
    public function index()
    {
    	$ajaxUrl = base_url().'Admin/Information/ajaxGetInfosList';
    	if($_POST){
    		$data = $this->input->post();
    		if(isset($data['name'])){
    			$ajaxUrl = $ajaxUrl.'?'.'name='.$data['name'];
    			$vdata['search_name'] = $data['name'];
    		}else{
                $ajaxUrl = $ajaxUrl.'?'.'type='.$data['type'].'&start_time='.$data['start_time'].'&end_time='.$data['end_time'];
            }
        }
        $vdata['ajaxUrl'] = $ajaxUrl;
        $this->load->view('Information/index',$vdata);
    }

	/**
	 * ajax获取用户列表
     * @DateTime 2017-09-04
     * @author xyl 
	 * @return [type] [description]
	 */
	public function ajaxGetInfosList()
    {
        $where = $_GET;
        $user_list = $this->infos->ajaxGetInfosList($_GET['iDisplayLength'],$_GET['iDisplayStart'],$where);
        $return = array(
            'aaData'=>$user_list['data'],
            'iTotalRecords'=>count($user_list['data']),
            'iTotalDisplayRecords'=>$user_list['total'],
        );
        echo json_encode($return);
    }

	/**
     * 获取符合条件的资讯
     * @DateTime 2017-09-06
     * @author xyl
     * @return [type]         [description]
     */
	public function getInfosList()
	{
		$post = $this->input->post();
		$list = $this->infos->getInfosList($post);
		echo json_encode($list);return;
	}



    /**
     * 添加或编辑资讯
     * @DateTime 2017-09-05
     * @author xyl
     */
    public function addInformation($info_id = false,$type = false)
    {
        $vdata = array();

        if ($_POST) {
            $post = $this->input->post();
            $res = $this->infos->addInformation($post);
            $this->handleResult($res);
        }else{
            $where = array(
                'status'    =>  1,
            );
            if (isset($info_id) && !empty($info_id)) {
                $vdata = $this->infos->getInfoDetail(array('id'=>$info_id),1);
                $where['id<>'] = $info_id;
            }
            if (isset($type) && !empty($type)) {
                $vdata['type'] = 1;
            }
            $vdata['info_list'] = $this->infos->ajaxGetInfosList(100,0,$where);
             // print_r($vdata);
            $this->load->view('Information/addInformation',$vdata);
        }
    }

    /**
     * 资讯上线下线，用于首页轮播显示
     * @DateTime 2017-09-05
     * @author xyl
     */
    public function setRoll()
    {
        $post = $this->input->post();
        $res = $this->infos->setRoll($post);
        $this->handleResult($res);
    }

    /**
     * 预览资讯
     * @DateTime 2017-09-05
     * @author xyl
     * @param  [type] $info_id [description]
     * @return [type]          [description]
     */
    public function preview($info_id)
    {
        $vdata['img_url'] = base_url().'Admin/Information/codeImg/'.$info_id;
        $vdata['info_id'] = $info_id;
        $this->load->view('Information/preview',$vdata);
    } 

    /**
     * 生成二维码
     * @DateTime 2017-09-05
     * @author xyl
     * @param  [type] $info_id     [description]
     * @return [type]              [description]
     */
    public function codeImg($info_id)
    {
        $this->load->helper('phpqrcode');
        $url = base_url().'Admin/Information/previewDetail/'.$info_id;
        // echo $url;die();
        $img =  QRcode::png($url,false,4,6);
        Header("Content-type: image/png");
        ImagePng($img);
        ImageDestroy($img);
    }

    /**
     * 预览详情
     * @DateTime 2017-09-05
     * @author xyl
     * @param  [type] $info_id [description]
     * @return [type]          [description]
     */
    public function previewDetail($info_id)
    {
        $vdata['info'] = $this->infos->getInfoDetail(array('id'=>$info_id));
        $this->load->view('Information/preview_detail',$vdata);
    }

}